package com.sojson.aspect;

import java.io.IOException;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import com.sojson.config.exception.TransErrorCode;
import com.sojson.constant.ConstantServlet;
import com.sojson.util.ExpUtil;
import com.sojson.util.param.ParamUtil;

/**
 * 登录验证注解处理
 * 
 * @author liu
 * @date 2021-05-06
 */
@Order(2)
@Aspect
@Component
public class LoginAspect implements PointcutsWebBase {

    /** 配置织入点 */
    @Pointcut("@annotation(" + ConstantServlet.PACKAGE_DEFAULT_ANNOTATION_ALL + ".Login)")
    public void pointCut() {}

    /**
     * 请求处理之前
     * 
     * @param joinPoint 切点
     * @throws IOException 
     */
    @Before("pointCut()")
    public void before(JoinPoint joinPoint) throws IOException {
        // 登录就结束
        if (ParamUtil.isLogin()) {
            return;
        }

        ExpUtil.throwEx(TransErrorCode.NOT_LOGIN);
    }

}